package com.itheima.idea.tist;

import com.itheima.idea.demain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class Test3<getStudent> {
    public static void main(String[] args) {
        //2.创建集合对象
        ArrayList<Student> list = new ArrayList<>();
        Student stu1 = getStudent(1);
        Student stu2 = getStudent(2);
        Student stu3 = getStudent(3);
        //5.往集合中添加学生对象
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        //6.遍历集合,采用通用遍历格式实现
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName() + "...." + stu.getAge());
        }
    }
        //当方法的返回值类型是一个类名时,方法中要返回的是该类的对象
        public static Student getStudent(int count){
            //3.键盘录入学生对象所需要的数据
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入" + count + "学生姓名:");
            String name = sc.next();
            System.out.println("请输入" + count + "学生年龄:");
            int age = sc.nextInt();
            //4.创建学生对象,把键盘录入的数据赋值给学生对象的成员变量
            Student stu = new Student(name, age);
            return stu;
        }
 }
